/*
 * 
 * 
 */


Ti.include('../main/wing_db.js');
Ti.include('../main/underscore.js');

var win = Titanium.UI.currentWindow;

var button1 = Ti.UI.createButton({
	height : 44,
	width : 200,
	title : 'Save kv',
	top : 20
});

var button2 = Ti.UI.createButton({
	height : 44,
	width : 200,
	title : 'Load kv',
	top : 90
});

var button3 = Ti.UI.createButton({
	height : 44,
	width : 200,
	title : '',
	top : 160
});

var button4 = Ti.UI.createButton({
	height : 44,
	width : 200,
	title : '',
	top : 230
});

button1.addEventListener('click', function() {
	var kv = new _kv();
	var sub1={};
	sub1.id='1';
	sub1.date='2012';
	sub1.money=1000;
	
	var sub2={};
	sub2.id='1';
	sub2.date='2012';
	sub2.money=2000;
	
	kv.set('1',sub1);
	kv.set('2',sub2);

	Ti.API.info('key 1:' + JSON.stringify(kv.get('1')));
	Ti.API.info('key 2:' + JSON.stringify(kv.get('2')));
	Ti.API.info('sub1 money:'+kv.get('1')["money"]);

	_save_kv(kv,'kvtest.txt');

})

button2.addEventListener('click', function() {
	
	var kv = _load_kv('kvtest.txt');
		
	Ti.API.info('key 1:' + JSON.stringify(kv.get('1')));
	Ti.API.info('key 2:' + JSON.stringify(kv.get('2')));
	Ti.API.info('sub1 money:'+kv.get('1')["money"]);

})

button3.addEventListener('click', function() {



})

button4.addEventListener('click', function() {



})

win.add(button1);
win.add(button2);
win.add(button3);
win.add(button4);
